#ifndef __CRC32__
#define __CRC32__

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define CRC32_BLOCK_SIZE 4096
#define CRC32_BLOCK_LENGTH (CRC32_BLOCK_SIZE/sizeof(uint64_t))

#define CRC32Q __builtin_ia32_crc32di /* 8 bytes */
#define CRC32L __builtin_ia32_crc32si /* 4 bytes */
#define CRC32W __builtin_ia32_crc32hi /* 2 bytes */
#define CRC32B __builtin_ia32_crc32qi /* 1 bytes */

// n < 4k
uint32_t crc32_n(const void *buf_, uint32_t size);
void crc32_4k_sequence(char* buf_, uint32_t size, uint32_t* out_crc32);
void crc32_4k_sequence_p2(char* buf_, uint32_t size, uint32_t* out_crc32);
void crc32_4k_sequence_p3(char* buf_, uint32_t size, uint32_t* out_crc32);
void crc32_4k_sequence_p4(char* buf_, uint32_t size, uint32_t* out_crc32);

#ifdef __cplusplus
}
#endif

#endif
